package com.gamejelly.broker.processor.event;


import com.alipay.remoting.Connection;
import com.alipay.remoting.ConnectionEventProcessor;
import com.gamejelly.broker.client.BrokerClient;
import com.gamejelly.broker.message.RegisterMsg;

import java.util.Map;

public class ConnHandler implements ConnectionEventProcessor {

    Map<String, BrokerClient> clients;

    @Override
    public void onEvent(String s, Connection connection) {
        String remoteAddress = connection.getRemoteIP()+":"+connection.getRemotePort();
        clients.entrySet().stream().filter((entry) -> entry.getValue().getBrokerAddress().equals(remoteAddress)).findFirst()
                .ifPresent((entry) -> {
                    RegisterMsg msg = new RegisterMsg();
                    msg.setRpcId(entry.getKey());
                    BrokerClient client = entry.getValue();
                });
    }

    public ConnHandler(Map<String, BrokerClient> clients) {
        this.clients = clients;
    }
}
